﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PBOffice.Model;
using System.Data.SqlClient;
using System.Data;

namespace PBOffice.DAL
{
    public class LoginService
    {
        /// <summary>
        /// 根据登录名跟密码查询管理员
        /// </summary>
        /// <param name="staff">管理员对象</param>
        /// <returns>管理员对象</returns>
         public Staff GetStaffParas(Staff staff)
        {
            string sql = "SELECT * FROM Staff WHERE StfName=@StfName and Password=@Password";
            SqlParameter[] paras = new SqlParameter[] { 
                new SqlParameter("@StfName",staff.StfName),
                new SqlParameter("@Password",staff.Password)
            };
            List<Staff> stafflist = new List<Staff>();
            using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, CommandType.Text, sql, paras))
            {
                while (reader.Read())
                {
                    Staff  sta = new Staff();
                    sta.StfId=(int)reader["StfId"];
                    sta.Password=reader["Password"].ToString();
                    sta.StfCode=reader["StfCode"].ToString();
                    sta.StfName=reader["StfName"].ToString();
                    sta.Gender=(bool)reader["Gender"];
                    sta.DeptId=(int)reader["DeptId"];
                    sta.PosId=(int)reader["PosId"];
                    sta.SuperId=(int)reader["SuperId"];
                    sta.Education=reader["Education"].ToString();
                    sta.WorkExp=reader["WorkExp"].ToString();
                    sta.BornDate=(DateTime)reader["BornDate"];
                    sta.JoinDate=(DateTime)reader["JoinDate"];
                    sta.Mail=reader["Mail"].ToString();
                    sta.TelePhone=reader["TelePhone"].ToString();
                    sta.TelePhoneExt=reader["TelePhoneExt"].ToString();
                    sta.MobilePhone=reader["MobilePhone"].ToString();
                    sta.Zip=reader["Zip"].ToString();
                    sta.Address=reader["Address"].ToString();
                    sta.Status=(byte)reader["Status"];
                    stafflist.Add(sta);
                }
            }
            if (stafflist.Count > 0)
                return stafflist[0];
            else
                return staff;
        }
    }
}
